<?php
/*
    Authors and license
*/
	
/*	Grabbing All user data and returning it as a table.
	Remember: $user_data[$i] is the value in sql database of column named $user_caption[$i] (local)
*/	
function grabUserData($id,$user_caption_amount) { // you must specify user Id, caption is grabbed from config
	$result = mysql_query("SELECT * FROM Users WHERE Id='$id'")
		or die("Error in database!"); 
	
	$row = mysql_fetch_array($result); // convert $result to single $row
		for($i=0;$i<$user_caption_amount;$i++) { 
			$user_data[$i] = $row[$i]; // cut $row to table
		}
	return $user_data; // return table
} // end of grabUserData()

/*	Updating all data about currently grabbed User to database
	Automatic, you just need to specify sources
	$user_caption_name = table that are holding headers
	$user_data = table of values of specific columns
	$user_caption_amount = size of both table, ofc WE CAN use simple sizeof($user_data), but that may cause some bugs
*/
function exportUserData($user_caption_name,$user_data,$user_caption_amount) {

	$query_string = "UPDATE Users SET ";
	
	$query_string .= $user_caption_name[1];
	$query_string .= "='";
	$query_string .= $user_data[1];
	$query_string .= "'";
	
	for($i=2;$i<$user_caption_amount;$i++)
	{
	$query_string .=  ", ";
	$query_string .= $user_caption_name[$i];
	$query_string .= "='";
	$query_string .= $user_data[$i];
	$query_string .= "'";
	}
	
	$query_string .= " WHERE ";
	$query_string .= $user_caption_name[0];
	$query_string .= "='";
	$query_string .= $user_data[0];
	$query_string .= "'";
	
	mysql_query($query_string);
} // end of updatePassword()

?>